package biz.impl;

import java.util.Date;
import java.util.List;

import biz.NewsBiz;
import dao.NewsDao;
import dao.impl.NewsDaoImpl;
import entity.News;

public class NewsBizImpl implements NewsBiz {

	private NewsDao newsDao = new NewsDaoImpl();
	
	@Override
	public List<News> findAllNews() {
		return newsDao.findAll();
	}

	@Override
	public boolean publishNews(News news) {
		try {
			news.setTime(new Date());
			int i = newsDao.saveNews(news);
			if(i>0) {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean deleteNews(int id) {
		try {
			int i = newsDao.deleteNews(id);
			if(i>0)
				return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return false;
	}

	@Override
	public News findById(int id) {
		return newsDao.findById(id);
	}

	@Override
	public boolean updateNews(News news) {
		int i = newsDao.updateNews(news);
		if(i>0) {
			return true;
		}
		return false;
	}

}
